
$(function(){
    $('#side-menu ul').eq(0).addClass('in');
    getCUserDetail();

    //获取帐号名称
    $('input[name=userAccount]').val(getUrlParam('account'));
    getOperateRecordList();
});


/**
 *  功能描述：获取详情
 *  请求方式：GET
 *  请求地址：/api/cuser/particular
 *  函数名称：getCUserDetail
 */

function getCUserDetail(){
    var id=getUrlParam("id");
    $.ajax({
        url:whole_path+'/api/cuser/particulars',
        type:'GET',
        cache:false,
        dataType:'json',
        data:{
            id:id
        },
        beforeSend:function(){
            $.progressBar({message:'<p>正在努力加载数据...</p>',modal:true,canCance:true});
        },
        success:function(data){
            if(data.status == 0){
                var json = data.data;
                $('span[name=username]').html(json.username);
                $('span[name=password]').html(json.password);
                $('span[name=phone]').html(json.phone);
                $('span[name=certName]').html(json.certName);
                $('span[name=carNumber]').html(json.carNumber);
                $('span[name=carType]').html(json.carType);
                $('span[name=carLength]').html(json.carLength);
                $('span[name=belongArea]').html(json.belongArea);
                $('span[name=runningRoute]').html(json.runningRoute);
                var status = json.carStatues;
                switch (status){
                    case 0:
                        status = '空车模式'
                        break;
                    case 1:
                        status = '满载模式'
                        break;
                    case 2:
                        status = '配货模式'
                        break;
                }
                $('span[name=carStatues]').html(status);
                //循环获取平台追加到platform_contain容器
                var temp = "";
                var list = json.loginLimits;
                $.each(list, function(index, item) {
                    var platform = item.platformType;
                    switch (platform){
                        case 1:
                            platform = "iOS"
                            break;
                        case 2:
                            platform = "Android"
                            break;
                    }
                    //只显示开通的平台
                    if (item.beUsed == 1){
                        temp += '<span class="text" >'+platform+'</span>&nbsp;<span class="text" >:'+timeFormat(item.expireTime)+'</span>&nbsp;'
                    }
                })
                $("#cuser_platform_contain").append(temp);

            }
        },
        complete:function(){
            $.progressBar().close();
        },
        error:function(XMLHttpRequest,textStatus,errorThrown){
            $.toast('服务器未响应，请稍候重试',5000);
        }
    });
}


/**
 *  功能描述：操作记录
 *  请求方式：GET
 *  请求地址：/api/record/list
 *  函数名称：getOperateRecordList
 */

function getOperateRecordList(){
    $.ajax({
        url: whole_path+'/api/record/list',
        type: 'GET',
        dataType: 'json',
        cache:false,
        data: $('#operate_record_form').serialize(),
        beforeSend:function(data){
            $.progressBar({message:'<p>正在努力加载数据...</p>',modal:true,canCancel:true});
        },
        success:function(data){
            if(data.status == 0) {
                var json = data.data;
                var list = json.result;
                var temp = "";
                if (list != null && list.length>0){
                    $.each(list, function (index, item) {
                        var userType = item.userType;
                        switch (userType){
                            case 1:
                                userType = '车主用户'
                                break;
                            case 2:
                                userType = '专线用户'
                                break;
                        }

                        temp += '<tr class="gradeA">'
                            + '<td data-title="账号">' + item.userAccount + '</td>'
                            + '<td data-title="用户类型">' + userType + '</td>'
                            + '<td data-title="操作内容">' + item.operateDescribe + '</td>'
                            + '<td data-title="操作时间">' + timestampFormat(item.createTime) + '</td>'
                            + '<td data-title="操作人">' + item.operateName + '</td>'
                            + '</tr>';
                    })
                    $('#operate_record_list tbody').html(temp);
                    page('#pagination', json.pagecount, json.pageindex, json.pagesize, getOperateRecordList, '#pageNum');

                }
                // else{
                //     $.toast("没有查到数据",3000);
                //     $('#operate_record_list tbody').html('');
                //     if($('#pagination').html().length > 0){
                //         $('#pagination').jqPaginator('destroy');
                //     }
                // }
            }
        },
        complete:function(){
            $.progressBar().close();
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
            $.toast('服务器未响应,请稍候重试',5000);
        }
    })
}